﻿package com.webdesign.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeChangeUtil {
	/*
	 * 把mm/dd/yyyy转化成yyyy-mm-dd
	 */
	public static String stringChange(String time) {
		String[] str = time.split("/");
		String timeChange = str[2] + "-" + str[0] + "-" + str[1];
		return timeChange;
	}

	/*
	 * 把yyyy-mm-dd转化成date格式
	 */
	public static Date toToday(String time) throws ParseException {
		/* 格式为hh:mm:ss */
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(time);
		return date;
	}

	/*
	 * 把Date格式转化成MM/DD/YYYY格式字符串
	 */
	public static String changeToString(Date time) {
		String changedTime = String.valueOf(time.getMonth()+1) + "/"
				+ String.valueOf(time.getDate()) + "/"
				+ String.valueOf(time.getYear()+1900);

		return changedTime;
	}
}
